package com.qf.smartplatform.service.impl;

import com.qf.smartplatform.mapper.RoleMapper;
import com.qf.smartplatform.pojo.BaseUser;
import com.qf.smartplatform.pojo.SysRole;
import com.qf.smartplatform.pojo.SysUserInfo;
import com.qf.smartplatform.service.RoleService;
import com.qf.smartplatform.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*** @author Tgb
 * @version V1.0
 * @Project smartplatform
 * @Package com.qf.smartplatform.service.impl
 * @Description:
 * @Date 2022/9/12 21:26
 */
@Service
public class RoleServiceImpl implements RoleService {
    private RoleMapper roleMapper;
    @Autowired
    public void setRoleMapper(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }

    @Override
    public void addRole(SysRole sysRole) {
        BaseUser loginUser = SecurityUtils.getUser();
        sysRole.setCreateBy(loginUser.getUsername());
//        sysRole.setCreateBy("woziji");
        roleMapper.addRole(sysRole);
    }

    @Override
    public SysRole findById(Long id) {
        return roleMapper.findById(id);
    }

    @Override
    public List<SysRole> findAll() {

        return roleMapper.findALl();
    }

    @Override
    public int deleteById(Long id) {
        roleMapper.deleteById(id);
        return 0;
    }

    @Override
    public int updateRole(SysRole sysRole) {
        BaseUser user = SecurityUtils.getUser();
        sysRole.setUpdateBy(user.getUsername());
//        sysRole.setUpdateBy("woziji");
        roleMapper.updateRole(sysRole);
        return 0;
    }

}
